import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
class App extends React.Component {
  render() {
    return (
      <div>
        <h1>Hello World</h1>
      </div>
    );
  }
}
class test {
  constructor() {
    this.listener = [];
  }
  addChangeListener(callback) {
    this.listener.push(callback);
  }
  publish(data) {
    for (let i = 0; i < this.listener.length; i++) {
      // 对应每一个订报纸的人
      const listener = this.listener[i];
      listener(data);
    }
  }
  removeChangeListener(callback) {
    const index = this.listener.indexOf(callback);
    if (index > -1) {
      this.listener.splice(index, 1);
    }
  }
}
function fn(data) {
  console.log("焦虑你我他", data);
}
function fn2(data) {
  console.log("开心你我他", data);
}
const test1 = new test();
test1.addChangeListener(fn);
test1.addChangeListener(fn2);
test1.publish("焦虑远离他");
test1.publish("焦虑别管他");

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<App />);
